package com.qfedu.edu.handler;

import com.qfedu.edu.context.Context;
import com.qfedu.edu.result.R;
import com.qfedu.edu.utils.HttpResponseUtils;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.logout.LogoutHandler;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Component
public class MyLogoutHandler implements LogoutHandler {
    @Override
    public void logout(HttpServletRequest request, HttpServletResponse response, Authentication authentication) {
        String token = request.getHeader("token");
        Context.getRoleAndPerm().remove(token);
        R ok = R.ok();
        HttpResponseUtils.sendResponse(response, ok);
    }
}
